<template>
	<view class="login-page">
		<zero-custom-bar title="登录" :effect='false' :fixedHolder='true' :singleIcon="true" backgroundColor='#FFF'>
			<view slot='left'></view>
		</zero-custom-bar>
		<view class="login-box">
			<view class="title-text">手机号：</view>
			<uni-easyinput v-model="phoneNum" type="number" :trim="true" primaryColor="#ffd589" :maxlength="100"
				placeholder="请输入手机号"></uni-easyinput>
			<view class="title-text">密码：</view>
			<uni-easyinput v-model="password" type="password" :trim="true" primaryColor="#ffd589" :maxlength="100"
				placeholder="请输入密码"></uni-easyinput>
			<!-- <view class="forget-btn" @click="toFindPassword">忘记密码？</view> -->
		</view>
		<view class="login-btn " @click="loginEvent">登录</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phoneNum: '',
				password: ''
			};
		},
		methods: {
			// 忘记密码
			toFindPassword() {
				uni.navigateTo({
					url: '/pages/find-password/find-password'
				})
			},

			// 登录
			loginEvent() {
				const data = {
					clientId: "083d755820eb8dfe38a2b424f4fb7cae",
					grantType: "xcxEmployeePassword",
					phonenumber: this.phoneNum,
					password: this.password,
					type:'store'
				}
				this.$request({
					method: 'post',
					url: '/auth/login',
					data,
					loading: true,
					isEncrypt: true
				}).then((res) => {
					if (res.code == 500) {
						uni.showToast({
							title: res.msg,
							duration: 2000,
							icon: 'none'
						})
					} else {
						const {
							access_token,
							client_id
						} = res.data
						uni.setStorageSync('token', access_token)
						uni.setStorageSync('clientId', client_id)
						uni.setStorageSync('phoneNum', this.phoneNum)
						uni.setStorageSync('password', this.password)
						uni.removeStorageSync('shopId')
						uni.reLaunch({
							url: '/pages/index/index'
						})
					}
				})
			},
			// 检查是否已登录
			checkedLogin() {
				let token = uni.getStorageSync('token')
				let clientId = uni.getStorageSync('clientId')
				if (token && clientId) {
					uni.reLaunch({
						url: '/pages/index/index'
					})
				}
			}
		},
		onLoad() {
			this.phoneNum = uni.getStorageSync('phoneNum') || ''
			this.password = uni.getStorageSync('password') || ''
			this.checkedLogin()
		}
	}
</script>

<style lang="scss">
	.login-page {
		height: 100vh;
		background: #FFF;
		padding: 40rpx;
		box-sizing: border-box;

		.login-title {
			font-weight: bold;
			font-size: 48rpx;
			color: #333333;
		}

		.login-box {
			.is-input-border {
				border: none !important;
				border-bottom: 1px solid #EEE !important;
				border-radius: 0 !important;
			}

			.uni-easyinput__content-input {
				padding-left: 0 !important;
				font-size: 32rpx;
			}

			.uni-easyinput__placeholder-class {
				font-size: 32rpx !important;
			}

			.uni-easyinput {
				margin-top: 50rpx;
			}

			.code-text {
				font-size: 30rpx;
				color: #ffd589;
				font-size: 30rpx;
			}
		}

		.login-btn {
			background: #ffd589;
			border-radius: 45rpx;
			font-size: 32rpx;
			color: #000;
			padding: 30rpx;
			text-align: center;
			margin-top: 100rpx;
		}

		.title-text {
			font-size: 28rpx;
			margin-top: 60rpx;
		}

		.forget-btn {
			text-align: right;
			font-weight: bold;
			font-size: 28rpx;
			color: #0096cd;
			margin-top: 10rpx;
		}
	}
</style>